<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
      }
    </style>
  </head>
  <body>
    <button>开关灯</button>
    <script>
      //1. 事件源
      var btn = document.querySelector('button');
      var body = document.querySelector('body');
      //2.事件类型
      var tf = true;
      btn.onclick = function () {
        //3.事件代码
        if (tf) {
          body.style.backgroundColor = 'black';
          tf = false;
        } else {
          body.style.backgroundColor = '';
          tf = true;
        }

        // body.style.backgroundColor = 'black';
      };

      
    </script>
  </body>
</html>
